# @before-stub-for-debug-begin
from python3problem150 import *
from typing import *
# @before-stub-for-debug-end

#
# @lc app=leetcode.cn id=150 lang=python3
#
# [150] 逆波兰表达式求值
#

from typing import List
# @lc code=start
class Solution:
    def evalRPN(self, tokens: List[str]) -> int:
        stack = []
        op = ['+', '-', '*', '/']
        for ch in tokens:
            if ch in op:
                num2 = stack.pop()
                num1 = stack.pop()
                if ch == '+':
                    stack.append(num1 + num2)
                elif ch == '-':
                    stack.append(num1 - num2)
                elif ch == '*':
                    stack.append(num1 * num2)
                elif ch == '/':
                    stack.append(int(float(num1) / num2))
            else:
                stack.append(int(ch))
        return stack.pop()

# @lc code=end

